package ioc

import (
	"gitee.com/chicken-c/go-learn/webook/internal/service"
	"gitee.com/chicken-c/go-learn/webook/job"
	"gitee.com/chicken-c/go-learn/webook/pkg/logger"
	"github.com/robfig/cron/v3"
	"time"
)

func InitRankingJob(svc service.RankingService) job.Job {
	//给定时任务30s的超时时间
	return job.NewRankingJob(svc, time.Second*30)
}

func InitJobs(l logger.Logger, rankingJob job.Job) *cron.Cron {
	Build := job.NewCronJobBuild(l)

	expr := cron.New(cron.WithSeconds())
	//每分钟执行一次定时任务
	_, err := expr.AddJob("@every 1m", Build.Build(rankingJob))
	if err != nil {
		panic(err)
	}

	return expr
}
